<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">
		<style type="text/css">
			#type5{
				display: none;
			}
			#sub_shop{
				display: none;
			}
			
			input::-webkit-outer-spin-button,
			input::-webkit-inner-spin-button {
			    -webkit-appearance: none;
			}
			 
			input[type="number"] {
			    -moz-appearance: textfield;
			}
			.layui-table th {
				position: relative;
				min-height: 20px;
				height: 35px;
				line-height: 20px;
				font-size: 14px;
				padding: 0px 0px;
			}

			.layui-table td {
				position: relative;
				min-height: 20px;
				height: 100%;
				line-height: 14px;
				font-size: 14px;
				padding: 0px 0px;
			}

			.layui-table .layui-input,
			.layui-table .layui-textarea {
				display: block;
				width: 100%;
				padding: 0px 0px;
				border: 0px;
			}

			.layui-table .layui-input {
				text-align: center;
			}

			.layui-form-item {
				margin-bottom: 12px;
			}

			.z_show_img_ul {}

			display: flex;
			align-items: center;
			flex-wrap: wrap;
			}

			.z_show_img_li {
				text-align: center;
			}

			.z_show_img_li p,
			.z_show_img_li1 p {
				text-align: center;
				cursor: pointer;
			}

			.z_show_img_li img {
				width: 30px;
				height: 30px;
				margin-bottom: 2px;
			}

			.layui-btn {
				height: 38px;
			}

			.choose_shopname {
				line-height: 38px;
			}
		</style>
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<div class="layui-input-inline" style="width: 100px;">
									<button type="button" class="layui-btn layui-btn-sm" onclick="chooseActive()">选择活动模板</button>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="width: 100px;"><span style="color:red;margin-right: 4px;">*</span>频道：</label>
								<div class="layui-input-inline" >
									<select lay-search="" lay-filter="channelid" lay-verify="" name="channelid" class="site_icon_group" id="channelid"></select>
								</div>
								<label class="layui-form-label" style="width: 100px;">是否显示：</label>
								<div class="layui-input-inline">
									<input type="radio" name="is_recommend" value="0" title="否" checked>
									<input type="radio" name="is_recommend" value="1" title="是">
								</div>
								<label class="layui-form-label" style="width: 100px;">倒计时：</label>
								<div class="layui-input-inline">
									<input type="radio" name="istimer" value="1" title="显示" checked>
									<input type="radio" name="istimer" value="0" title="不显示">
								</div>
								<label class="layui-form-label" style="width: 100px;">客户端：</label>
								<div class="layui-input-inline icon_type" style="width: 250px;"></div>
								
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="width: 100px;">活动标题：</label>
								<div class="layui-input-inline">
									<input type="text" name="title" class="layui-input" id="title" autocomplete="off" placeholder="标题：">
								</div>
								
								<label class="layui-form-label" style="width: 100px;"><span style="color:red;margin-right: 4px;">*</span>活动状态：</label>
								<div class="layui-input-inline on_off"></div>
								<label class="layui-form-label" style="width: 100px;">活动名称：</label>
								<div class="layui-input-inline">
									<input type="text" name="name" class="layui-input" id="name" autocomplete="off" placeholder="名称">
								</div>
								<label class="layui-form-label" style="width: 100px;">排序：</label>
								<div class="layui-input-inline">
									<input type="text" name="oid" class="layui-input" id="oid" autocomplete="off"
										placeholder="排序">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="width: 100px;">开始日期：</label>
								<div class="layui-input-inline">
									<input type="text" name="dates" class="layui-input" id="dates" autocomplete="off" placeholder="开始日期：">
								</div>
								<label class="layui-form-label" style="width: 100px;">开始时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="times" class="layui-input" id="times" autocomplete="off" placeholder="开始时间：">
								</div>
								<label class="layui-form-label" style="width: 100px;">结束时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="endtime" class="layui-input" id="endtime"
										autocomplete="off" placeholder="结束时间：">
								</div>
							</div>
							<div id="type5">
								<div class="layui-form-item">
									<label class="layui-form-label" style="width: 100px;"><span style="color:red;margin-right: 4px;">*</span>参与周期：</label>
									<div class="layui-input-inline">
										<select id="cycle" name="cycle" class="cycle">
											<option value="">--未选择--</option>
											<option value="0">单次</option>
											<option value="1">每天</option>
											<option value="2">每周</option>
											<option value="3">每月</option>
										</select>
									</div>
									<label class="layui-form-label" style="width: 100px;">周期参与次数：</label>
									<div class="layui-input-inline">
										<input type="text" name="top_count5" class="layui-input" id="top_count5" autocomplete="off" placeholder="周期参与次数，0为不限次数">
									</div>
									<label class="layui-form-label" style="width: 100px;">消耗账户：</label>
									<div class="layui-input-inline">
										<select id="pay_account" name="pay_account" class="pay_account">
											<option value="">--未选择--</option>
											<option value="100">余额帐户</option>
											<option value="101">消费积分</option>
											<option value="103">佣金账户</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label" style="width: 100px;">单次消耗金额：</label>
									<div class="layui-input-inline">
										<input type="number" name="pay_fee" class="layui-input" id="pay_fee" autocomplete="off" placeholder="单次抽奖消耗">
									</div>
									<label class="layui-form-label" style="width: 100px;">活动中奖率：</label>
									<div class="layui-input-inline">
										<input type="number" name="prize_rate" class="layui-input" id="prize_rate" autocomplete="off" placeholder="例:0.01(百分之一)">
									</div>
									<label class="layui-form-label" style="width: 100px;">活动商品数：</label>
									<div class="layui-input-inline">
										<input type="number" oninput="if(value> 8)value=8" name="quantity" class="layui-input" id="quantity" autocomplete="off" placeholder="最多8个商品">
									</div>
								</div>
							</div>
							<div id="type">
								<div class="layui-form-item">
									<label class="layui-form-label" style="width: 100px;">商品排列：</label>
									<div class="layui-input-inline">
										<input type="radio" name="sorted" value="0" title="竖排" checked>
										<input type="radio" name="sorted" value="1" title="横排">
									</div>
									<label class="layui-form-label" style="width: 100px;"><span style="color:red;margin-right: 4px;">*</span>主题色：</label>
									<div class="layui-input-inline">
										<input type="text" value="" placeholder="活动主题色" class="layui-input" id="color"
											name='color'>
									</div>
									<div class="layui-inline" style="left: -11px;">
										<div id="test-form"></div>
									</div>
									<label class="layui-form-label" style="width: 100px;">单人购买上限：</label>
									<div class="layui-input-inline">
										<input type="text" name="top_count5" class="layui-input" id="top_count5" autocomplete="off" placeholder="单人购买上限">
									</div>
								</div>
								<!-- <div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">频道</label>
										<div class="layui-input-inline">
											<select lay-search="" lay-filter="channelid" lay-verify="" name="channelid" class="site_icon_group" id="channelid"></select>
										</div>
									</div> 
								</div> -->
								<!-- <div class="layui-form-item">
									<label class="layui-form-label">是否显示</label>
									<div class="layui-input-inline">
										<input type="radio" name="recommend" value="0" title="否" checked>
										<input type="radio" name="recommend" value="1" title="是">
									</div>
								</div> -->
								<!-- <div class="layui-form-item">
									<label class="layui-form-label">活动名称：</label>
									<div class="layui-input-block">
										<input type="text" name="name" class="layui-input" id="name" autocomplete="off" placeholder="名称">
									</div>  
								</div> -->
								<!--<div class="layui-form-item">
									<label class="layui-form-label">模板链接：</label>
									<div class="layui-input-block">
										<input type="text" name="url" class="layui-input" id="url" autocomplete="off" placeholder="模板链接">
									</div>  
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">详情页链接：</label>
									<div class="layui-input-block">
										<input type="text" name="url_detail" class="layui-input" id="url_detail" autocomplete="off" placeholder="详情页链接">
									</div>  
								</div>-->

								<!-- <div class="layui-form-item">
									<label class="layui-form-label">首页倒计时</label>
									<div class="layui-input-inline">
										<input type="radio" name="istimer" value="1" title="显示" checked>
										<input type="radio" name="istimer" value="0" title="不显示">
									</div>
								</div> -->

								<!--店铺选择-->
								<!--<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">店铺名称</label>
										<div class="layui-input-inline">
											<input type="text" name="shopname" placeholder="请输入店铺名称" autocomplete="off" class="layui-input" lay-verify="required">
										</div> 
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">店铺编号</label>
										<div class="layui-input-inline">
											<input type="text" name="shopid" placeholder="请输入店铺编号" autocomplete="off" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux"><a href="Javascript:;" onclick="searchdata('shopid')">选择</a></div>
									</div>
								</div>-->
							</div>
							
								<div class="layui-form-item" style="display: none;">
									<div class="layui-inline">
										<label class="layui-form-label">活动类型:</label>
										<div class="layui-input-inline">
											<select id="seckill_type" name="type" class="seckill_type">
											</select>
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">专属等级</label>
										<div class="layui-input-inline">
											<select name="grade" class="site_union">
											</select>
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label" style="width: 100px;">活动内容：</label>
									<div class="layui-input-inline" style="width: 520px;">
										<input type="text" name="content" class="layui-input" lay-verify="content" autocomplete="off" placeholder="活动内容">
									</div>
									<label class="layui-form-label" style="width: 100px;">备注：</label>
									<div class="layui-input-inline" style="width: 520px;">
										<input type="text" name="content" class="layui-input" lay-verify="notes" autocomplete="off" placeholder="备注">
									</div>
									<div id="sub_shop"></div>
								</div>
								<div class="layui-form-item" id="commission">
									<label class="layui-form-label" style="width: 100px;">佣金模板：</label>
									<div class="layui-inline">
										<select id="select" style="border: 1px solid #000;" lay-filter="level">
											<option id="selectOp" value="">请选择一个佣金模板</option>
										</select>
									</div>
									<button type="button" class="layui-btn layui-btn-sm" onclick="resetNum()">全部重算</button>
									<button type="button" class="layui-btn layui-btn-sm" onclick="copypromotion()">复制旧活动</button>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label"><span style="color:red;margin-right: 4px;">*</span>图标</label>
									<div class="layui-input-inline">
										<button type="button" class="layui-btn layui-btn-normal"
											onclick="choose(1)">上传图标</button><span style="color:red">
											<p>建议上传340*220大小图片</p>
										</span>
									</div>
									<div class="layui-input-inline" style="width: 60px;">
										<ul class="z_show_img_ul" id="icon_url"></ul>
									</div>
									<label class="layui-form-label"><span style="color:red;margin-right: 4px;">*</span>主图</label>
									<div class="layui-input-inline">
										<button type="button" class="layui-btn layui-btn-normal"
											onclick="choose(2)">上传图片</button><span style="color:red">
											<p>建议上传750*375大小图片</p>
										</span>
									</div>
									<div class="layui-input-inline" style="width: 60px;">
										<ul class="z_show_img_ul" style="float: left;" id="img_url"></ul>
									</div>
								</div>

								<!-- <div class="layui-form-item">
									<label class="layui-form-label">主图<span style="color:red">*</span></label>
									<div class="layui-input-block">
										<button type="button" class="layui-btn layui-btn-normal" onclick="choose(2)">上传图片</button><span style="color:red"><p>建议上传750*375大小图片</p></span>
										<ul class="show_img_ul" id="img_url"></ul>
									</div>
								</div> -->


								<!-- <div class="layui-form-item">
									<label class="layui-form-label">商品排列方式</label>
									<div class="layui-input-inline">
										<input type="radio" name="sorted" value="0" title="竖排" checked>
										<input type="radio" name="sorted" value="1" title="横排">
									</div>
								</div> -->

								<!-- <div class="layui-form-item">
									<label class="layui-form-label">活动内容：</label>
									<div class="layui-input-block">
										<textarea class="layui-textarea" name="content" lay-verify="content" id=""></textarea>
									</div>
								</div> -->
								<!-- 	<div class="layui-form-item">
									<label class="layui-form-label">开始日期：</label>
									<div class="layui-input-inline">
										<input type="text" name="dates" class="layui-input" id="dates" autocomplete="off" placeholder="开始日期：">
									</div>
									<label class="layui-form-label">开始时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="times" class="layui-input" id="times" autocomplete="off" placeholder="开始时间：">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">结束时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="endtime" class="layui-input" id="endtime" autocomplete="off" placeholder="结束时间：">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">单人购买上限：</label>
									<div class="layui-input-block">
										<input type="text" name="top_count" class="layui-input" id="top_count" autocomplete="off" placeholder="单人购买上限">
									</div>  
								</div> -->

								<!-- <div class="layui-form-item">
									<label class="layui-form-label">备注</label>
									<div class="layui-input-block">
										<textarea type="text" id="notes" name="notes" autocomplete="off" placeholder="备注：" class="layui-textarea" /></textarea>
									</div>
								</div> -->
								<div class="layui-form-item">
									<label class="layui-form-label">列表链接：</label>
									<div class="layui-input-block">
										<input type="text" name="url" class="layui-input" id="url" autocomplete="off"
											placeholder="列表链接">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">详情链接：</label>
									<div class="layui-input-block">
										<input type="text" name="url_detail" class="layui-input" id="url_detail"
											autocomplete="off" placeholder="详情链接">
									</div>
								</div>
								<!-- <div class="layui-form-item">
									<label class="layui-form-label">排序：</label>
									<div class="layui-input-block">
										<input type="text" name="oid" class="layui-input" id="oid" autocomplete="off" placeholder="排序">
									</div>  
								</div> -->
							</div>
					</div>
					<div class="layui-card">
						<div class="layui-card-body" id="goodslist"></div>
						<script type="text/html" template id="goodslistTpl">
						{{# if(d.type == 1 || d.type == 2 || d.type == 4){ }}
							<table class="layui-table" id="testtable">
								<!--<table class="layui-table" lay-size="sm">-->
								<colgroup>
									<col>
									<col>
									<col>
									<col>
									<col>
								</colgroup>

								<thead>
									<tr>
										<th style="width: 40px;"></th>
										<th style="width: 60px;">编号</th>
										<th style="width: 15%;">商品名</th>
										<th>成本价</th>
										<th>会员价</th>
										<th>原抵扣积分</th>
										<th>秒杀价</th>
										<!-- <th>积分比例%</th> -->
										<th>积分使用</th>
										<th>抢购数量</th>
										<th>已抢购数量</th>
										<th>购买上限</th>
										<th>显示数量</th>

										<th>直推佣金</th>
										<th>间推佣金</th>
										<th>团长佣金</th>
										<th>管理奖</th>
										<th>合伙人佣金</th>
										<th>服务站佣金</th>

										<th>排序</th>

										<th style="width: 40px;">操作</th>
										<th style="width: 40px;">状态</th>
									</tr>
								</thead>

								<tbody id="temp">
									<tr id="tempTr">
										<td></td>
										<td style="width: 60px;">
											<div class="flex">
												<!-- <input class="layui-input layui-input-choose" onfocus="choosedata()" name="" value="zhu" /> -->
												<button type="button" class="layui-btn layui-btn-sm"
													onclick="choosedata()"><i
														class="layui-icon layui-icon-search"></i></button>
											</div>
										</td>
										<td style="width: 15%;"></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<!-- <td></td> -->
										<td></td>
										<td></td>
										<td></td>
										<!--<td></td>-->
										<td></td>

										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>

										<td></td>
									</tr>
								</tbody>
							</table>
							{{# } else if(d.type == 3 || d.type == 6) { }}
								<table class="layui-table" id="testtable">
									<!-- <table class="layui-table" lay-size="sm"> -->
									<colgroup>
										<col>
										<col>
										<col>
										<col>
										<col>
									</colgroup>

									<thead>
										<tr>
											<th style="width: 40px;"></th>
											<th style="width: 60px;">编号</th>
											<th style="width: 250px;">商品名</th>
											<th style="width: 70px;">成本价</th>
											<th style="width: 70px;">会员价</th>
											<!-- <th>原抵扣积分zhu</th> -->
											<th style="width: 70px;">团购价</th>
											<!-- <th>积分比例%zhu</th> -->
											<!-- <th>积分使用zhu</th> -->
											<th style="width: 70px;">补贴</th>
											<th style="width: 70px;">团人数</th>
											<th style="width: 70px;">中奖人数</th>
											<th style="width: 120px;">显示已参团数</th>

											<th style="width: 70px;">活动数量</th>
											<th style="width: 120px;">显示已购数量</th>
											<th style="width: 70px;">购买上限</th>
											<th style="width: 70px;">显示数量</th>

											<th style="width: 60px;">团时长</th>
											<th style="width: 90px;">发起佣金</th>

											<th style="width: 60px;">成团后抽奖人数</th>
											<th style="width: 200px;">成团后抽奖商品</th>

											<th style="width: 90px;">直推佣金</th>
											<th style="width: 90px;">间推佣金</th>
											<th style="width: 90px;">团长佣金</th>
											<th style="width: 90px;">管理奖</th>
											<th style="width: 100px;">合伙人佣金</th>
											<th style="width: 100px;">服务站佣金</th>
											<th style="width: 40px;">排序</th>
											<th style="width: 40px;">操作</th>
											<th style="width: 40px;">状态</th>
										</tr>
									</thead>

									<tbody id="temp">
										<tr id="tempTr">
											<td></td>
											<td style="width: 60px;">
												<div class="flex">
													<!-- <input class="layui-input layui-input-choose" onfocus="choosedata()" name="" value="zhu" /> -->
													<button type="button" class="layui-btn layui-btn-sm"
														onclick="choosedata()"><i
															class="layui-icon layui-icon-search"></i></button>
												</div>
											</td>
											<td style="width: 250px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 120px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 120px;"></td>

											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 60px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 100px;"></td>
											<td style="width: 100px;"></td>
											<td style="width: 40px;"></td>
											<td style="width: 40px;"></td>
											<td style="width: 40px;"></td>
											<td style="width: 40px;"></td>
											<td style="width: 40px;"></td>
										</tr>
									</tbody>
								</table>
								{{# } else if(d.type == 5) { }}
								<table class="layui-table" id="testtable">
									<colgroup>
										<col>
										<col>
										<col>
										<col>
										<col>
									</colgroup>
									<thead>
										<tr>
											<th style="width: 40px;"></th>
											<th style="width: 60px;">编号</th>
											<th style="width: 60px;">类型</th>
											<th style="width: 250px;">商品名</th>
											<th style="width: 90px;">最大中奖次数/数量</th>
											<th style="width: 90px;">单人最大中奖数量</th>
											<th style="width: 90px;">商品中奖率</th>
											<th style="width: 40px;">排序</th>
											<th style="width: 40px;">操作</th>
											<th style="width: 40px;">状态</th>
										</tr>
									<tbody id="temp">
										<tr id="tempTr">
											<td></td>
											<td style="width: 60px;">
												<div class="flex">
													<button type="button" class="layui-btn layui-btn-sm" onclick="choosedata()"><i class="layui-icon layui-icon-search"></i></button>
													<button type="button" class="layui-btn layui-btn-sm" onclick="choosedata1()"><i class="layui-icon layui-icon-addition"></i></button>
												</div>
											</td>
											<td style="width: 60px;"></td>
											<td style="width: 250px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 40px;"></td>
											<td style="width: 40px;"></td>
									</tbody>
								</table>
								{{# } }}
						</script>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id'),
			}
			var _member = {

			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'colorpicker'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					layedit = layui.layedit,
					colorpicker = layui.colorpicker;
				form = layui.form;
				var skuidArr = [];
				var img_arr1 = [],
					img_arr2 = [];
				on_off_show('radio')
				seckill_type_show("option")
				site_union_show("option")
				icon_type_show('checkbox')
				//日期时间选择器
				laydate.render({
					elem: '#dates',
					type: 'date'
				});
				//日期时间选择器
				laydate.render({
					elem: '#times',
					type: 'time'
				});
				//日期时间选择器
				laydate.render({
					elem: '#endtime',
					type: 'datetime'
				});
				//表单赋值
				colorpicker.render({
					elem: '#test-form',
					done: function(color) {
						$('#color').val(color);
					}
				});

				$.get(server.queryshopmodulelist, {
					page: 1,
					limit: 99,
					filterRules: [],
					sort: [],
					method: 'channel.index',
					fid: ''
				}, function(res, status) {
					if (status == 'success') {
						if (res.code == 0) {
							var data = res.module_list.data;
							//data.shift()
							var rolehtml = "<option value=''>请选择</option>";
							for (var i = 0; i < data.length; i++) {
								rolehtml += '<option value=' + data[i].id + '>' + data[i].title + '</option>'
							}
							$(".site_icon_group").append(rolehtml);
							form.render('select')
							form.render('radio')

						}
						closeloading();
					} else {
						layer.msg('服务器连接错误');
					}
				});

				if (_data.id) {
					setTimeout(function() {
						initdata();
					}, 300)
				}

				window.tempList = []
				// 获取模板数据
				// window.getTempLate()
				getTempLate = function() {
					$.post(server.shop_feetemp_list, {}, function(res, status) {
						if (res.code === 0) {
							let data = res.seckill_fee_temp.data;
							window.tempList = data
							let html = '';
							for (var i = 0; i < data.length; i++) {
								html += `<option value="${data[i].id}">${data[i].name}</option>`
							}
							$("#selectOp").after(html)
							form.render();
						}
					})
				}
				getTempLate()



				//监听提交
				form.on('submit(demo1)', function(data) {
					var list = [];
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.icon_url = img_arr1.join(',');
					_data.img_url = img_arr2.join(',');
					_data.client = ''
					for (item in data) {
						if (/^c/.test(item)) {
							if (item.substr(0, 6) == 'client') {
								_data.client += data[item] + ','
							}
						}
					}
					_data.client = (_data.client.substring(_data.client.length - 1) == ',') ? _data.client.substring(0, _data.client.length - 1) : _data.client;
					var request_data = [];
					var testtable = document.getElementById('testtable');
					var rows = testtable.rows;
					if (_data.type == '1' || _data.type == '2' || _data.type == '4') { //秒杀 积分
						for (var i = 0; i < rows.length; i++) {
							var row = rows[i];
							var cells = row.cells;
							var obj_id = $(row).attr('id')
							if (!obj_id) continue;
							var skuid = $(cells).find('input[name=skuid]').val(),
								goods_name = $(cells).find('input[name=goods_name]').val(),
								price = $(cells).find('input[name=price]').val(),
								cost_price = $(cells).find('input[name=cost_price]').val(),
								stock = $(cells).find('input[name=stock]').val(),
								sales = $(cells).find('input[name=sales]').val(),
								num = $(cells).find('input[name=num]').val(),
								score = $(cells).find('input[name=score]').val(),
								score_scale = $(cells).find('input[name=score_scale]').val(),
								top_count = $(cells).find('input[name=top_count]').val();
								leader_fee = $(cells).find('input[name=leader_fee]').val(), // 团长佣金
								direct_fee = $(cells).find('input[name=direct_fee]').val(), // 直推奖励
								indirect_fee = $(cells).find('input[name=indirect_fee]').val(), /* 间推奖励 */
								team_fee = $(cells).find('input[name=team_fee]').val(), // 团队奖励 === 管理奖
								copartner_fee = $(cells).find('input[name=copartner_fee]').val(), // 合伙人奖励
								station_fee = $(cells).find('input[name=station_fee]').val(), // 服务站奖励
								oid = $(cells).find('input[name=oid]').val();
							if (skuid) {
								var seckill_goods = {
									'obj_id': obj_id,
									'channelid': _data.channelid,
									'subshopid': _data.subshopid,
									'subshopname': _data.subshopname,
									'skuid': skuid,
									'goods_name': goods_name,
									'cost_price': cost_price,
									'price': price,
									'stock': stock,
									'num': num,
									'score': score,
									'score_scale': score_scale,
									'top_count': top_count,
									'sales': sales,
									'leader_fee': leader_fee,
									'direct_fee': direct_fee,
									'indirect_fee': indirect_fee,
									'team_fee': team_fee,
									'copartner_fee': copartner_fee,
									'station_fee': station_fee,
									'oid': oid
								};
								if (_data.id) {
									var rowdata = JSON.parse(unescape($(row).attr("rowdata")));
									if (rowdata.seckill_id) {
										seckill_goods.id = rowdata.id
									}
								}
								request_data.push(seckill_goods)
							}
						}
					} else if (_data.type == '3' || _data.type == '6') { //拼团
						for (var i = 0; i < rows.length; i++) {
							var row = rows[i];
							var cells = row.cells;
							var obj_id = $(row).attr('id')
							if (!obj_id) continue;
							var skuid = $(cells).find('input[name=skuid]').val(),
								goods_name = $(cells).find('input[name=goods_name]').val(),
								cost_price = $(cells).find('input[name=cost_price]').val(), //成本价
								price = $(cells).find('input[name=price]').val(), //团购价格
								stock = $(cells).find('input[name=stock]').val(), //库存数量
								sales = $(cells).find('input[name=sales]').val(), //已购买数量
								num = $(cells).find('input[name=num]').val(), //显示数量
								//score = $(cells).find('input[name=score]').val(),
								//score_scale = $(cells).find('input[name=score_scale]').val(), 
								top_count = $(cells).find('input[name=top_count]').val(), //购买上限
								subsidy = $(cells).find('input[name=subsidy]').val(), //补贴
								group_num = $(cells).find('input[name=group_num]').val(), //团人数
								group_wnum = $(cells).find('input[name=group_wnum]').val(), //中奖人数
								group_onum = $(cells).find('input[name=group_onum]').val(), //显示团参与人数
								duration = $(cells).find('input[name=duration]').val(),
								launch_fee = $(cells).find('input[name=launch_fee]').val(),
								leader_fee = $(cells).find('input[name=leader_fee]').val(), // 团长佣金
								direct_fee = $(cells).find('input[name=direct_fee]').val(), // 直推奖励

								group_after_lottery_people = $(cells).find('input[name=group_after_lottery_people]').val(), // 直推奖励
								group_after_lottery_skuid = $(cells).find('input[name=group_after_lottery_skuid]').val(), // 直推奖励

								indirect_fee = $(cells).find('input[name=indirect_fee]').val(),
								/* 间推奖励 */
								team_fee = $(cells).find('input[name=team_fee]').val(), // 团队奖励 === 管理奖
								copartner_fee = $(cells).find('input[name=copartner_fee]').val(), // 合伙人奖励
								station_fee = $(cells).find('input[name=station_fee]').val(), // 服务站奖励
								oid = $(cells).find('input[name=oid]').val();

							if (group_after_lottery_people > 0 && !group_after_lottery_skuid) {
								layer.msg('第[' + (i) + ']行请添加抽奖商品');
								return false;
							}

							if (group_after_lottery_people <= 0 && group_after_lottery_skuid) {
								layer.msg('第[' + (i) + ']行成团后抽奖人数需大于0');
								return false;
							}
							
							if (skuid) {
								var seckill_goods = {
									'obj_id': obj_id,
									'channelid': _data.channelid,
									'subshopid': _data.subshopid,
									'subshopname': _data.subshopname,
									'skuid': skuid,
									'goods_name': goods_name,
									'cost_price': cost_price,
									'price': price,
									'subsidy': subsidy,
									'group_num': group_num,
									'group_wnum': group_wnum,
									'group_onum': group_onum,
									'stock': stock,
									'num': num,
									'group_after_lottery_skuid' : group_after_lottery_skuid,
									'group_after_lottery_people' : group_after_lottery_people, 
									'top_count': top_count,
									'sales': sales,
									'duration': duration,
									'launch_fee': launch_fee,
									'leader_fee': leader_fee,
									'direct_fee': direct_fee,
									'indirect_fee': indirect_fee,
									'team_fee': team_fee,
									'copartner_fee': copartner_fee,
									'station_fee': station_fee,
									'oid': oid
								};
								if (_data.id) {
									var rowdata = JSON.parse(unescape($(row).attr("rowdata")));
									if (rowdata.seckill_id) {
										seckill_goods.id = rowdata.id
										//seckill_goods.seckill_id = rowdata.seckill_id
									}
								}
								request_data.push(seckill_goods)
							}
						}
					} else if (_data.type == '5'){ // 抽奖
						for (var i = 0; i < rows.length; i++) {
							var row = rows[i];
							var cells = row.cells;
							var obj_id = $(row).attr('id')
							if (!obj_id) continue;
							var skuid = $(cells).find('input[name=skuid]').val(),
								type = $(cells).find('input[name=goods_type]').val(),
								goods_name = $(cells).find('input[name=goods_name]').val(),
								stock = $(cells).find('input[name=stock]').val(), //最大中奖次数
								top_count = $(cells).find('input[name=top_count]').val(), //单人最大中奖数量
								prize_rate = $(cells).find('input[name=goods_prize_rate]').val(), //商品中奖率
								oid = $(cells).find('input[name=oid]').val();
							if($.inArray(oid,list) != -1){
								layer.msg('奖品排序不能重复');
								return false;
							} else {
								list.push(oid)
							};
							if (skuid) {
								var seckill_goods = {
									'obj_id': obj_id,
									'channelid': _data.channelid,
									'subshopid': _data.subshopid,
									'subshopname': _data.subshopname,
									'skuid': skuid,
									'type': type,
									'goods_name': goods_name,
									'stock': stock,
									'top_count': top_count,
									'prize_rate': prize_rate,
									'oid': oid
								};
								if (_data.id) {
									var rowdata = JSON.parse(unescape($(row).attr("rowdata")));
									if (rowdata.seckill_id) {
										seckill_goods.id = rowdata.id
										//seckill_goods.seckill_id = rowdata.seckill_id
									}
								}
								request_data.push(seckill_goods)
							}
						}
					}
					if (!request_data || request_data.length < 1) {
						layer.msg('请添加活动商品');
						return false;
					}
					_data.goods_data = JSON.stringify(request_data)
					_data.top_count = _data.top_count5
					layer.confirm('确定要提交数据？', function() {
						loading();
						if (_data.id) {
							editpromotion(_data, request_data);
						} else {
							delete _data.id
							submitdata(server.shop_promotion_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function editpromotion(_data, goods_data) {
					//loading();
					$.ajaxSettings.async = false;
					//var goods_data = _data.goods_data
					
					//alert("开始修改！");
					for (var p in goods_data) {
						var goods = goods_data[p]
						var obj_id = goods.obj_id
						//alert(obj_id);
						if (obj_id) {
							$('#rowstatus' + obj_id).innerHTML = ''
							if (goods.id) { //修改
								//alert("修改"+JSON.stringify(goods));
								$.post(server.seckill_goods_edit, goods, function(res, status) {
									if (status == 'success') {
										if (res.code == 0) {
											$('#rowstatus' + obj_id).innerHTML = '√'
										} else {
											$('#rowstatus' + obj_id).innerHTML = '×'
										}
									} else {
										$('#rowstatus' + obj_id).innerHTML = '×'
									}
								});
							} else { //添加
								goods.seckill_id = _data.id
								//alert("添加"+JSON.stringify(goods));
								$.post(server.shop_promotion_goods_add, goods, function(res, status) {
									if (status == 'success') {
										if (res.code == 0) {
											//alert(JSON.stringify(res.data));
											$('#rowstatus' + obj_id).innerHTML = '√'
										} else {
											$('#rowstatus' + obj_id).innerHTML = '×'
										}
									} else {
										$('#rowstatus' + obj_id).innerHTML = '×'
									}
								});
							}
						}
					}

					$.post(server.seckill_edit, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('保存成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg('保存失败！');
							}
						} else {
							layer.msg('服务器连接错误！');
						}
					});

					$.ajaxSettings.async = true;
					closeloading();
					//layer.msg('暂不支持修改')
				}

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					$.get(server.shop_promotion_detail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								res.seckill.data['is_recommend'] = res.seckill.data.recommend
								var data = res.seckill.data
								if(data.type == 5){
									$("#type").hide();
									$("#commission").hide();
									$("#type5").show();
									$('#sub_shop').hide();
								}
								data.top_count5 = data.top_count
								if (res.seckill_goods && res.seckill_goods.data) {
									data.seckill_goods = res.seckill_goods.data
								}
								setformdata(data);
								// data.data.icon_url ? createli(data.data.icon_url, 'icon_url', '1') : '';
								// data.data.img_url ? createli(data.data.img_url, 'img_url', '2') : '';

								// if(data.data.channelid){
								// 	$("#channelid option[value='"+data.data.channelid+"']").prop("selected","selected");
								// }
								// form.val("test_detail", data.data);
								// form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				window.searchdata = function(type) {
					switch (type) {
						case 'shopid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_shop.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}

				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				
				// 选择积分或余额
				window.choosedata1 = function() {
					var type = $("#seckill_type").val()
					var url = $("#url").val()
					var channelid = $("#channelid").val()
					var quantity = $("input[name=quantity]").val()
					if (!type || !url || url == '') {
						layer.msg('请先选择一个活动模板');
						return false;
					}
					if (!channelid || channelid == '') {
						layer.msg('请先选择一个活动频道');
						return false;
					}
					if (type==5 && !quantity){
						layer.msg('请先填写活动商品数');
						return false;
					}
					if (type==5 && ($("#temp tr").length > quantity)){
						layer.msg('超出商品上限');
						return false;
					}
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['400px', '200px'],
						content: 'list_prize.html',
						end: function() {},
						success: function() {}
					});
				}
				
				// 选择商品
				var $chooseAfterLotterySkuid = ''
				window.choosedata = function(chooseAfterLotterySkuidFlag, currentTarget) {
					if (chooseAfterLotterySkuidFlag) {
						console.log('=================')
						$chooseAfterLotterySkuid = $(currentTarget)
						console.log($chooseAfterLotterySkuid)
					}

					var type = $("#seckill_type").val()
					var url = $("#url").val()
					var channelid = $("#channelid").val()
					var quantity = $("input[name=quantity]").val()
					//alert(type);
					if (!type || !url || url == '') {
						layer.msg('请先选择一个活动模板');
						return false;
					}

					if (!channelid || channelid == '') {
						layer.msg('请先选择一个活动频道');
						return false;
					}
					if (type==5 && !quantity){
						layer.msg('请先填写活动商品数');
						return false;
					}
					if (type==5 && ($("#temp tr").length > quantity)){
						layer.msg('超出商品上限');
						return false;
					}
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['80%', '80%'],
						content: 'list.html?channelid=' + channelid + "&chooseAfterLotterySkuidFlag=" + chooseAfterLotterySkuidFlag,
						end: function() {},
						success: function() {}
					});
				}

				window.setChooseAfterLotterySkuid = function(skuData) {
					console.log(skuData)
					if (skuData.length > 0) {
						$chooseAfterLotterySkuid.val(skuData[0].skuid)
					}
				}

				window.copypromotion = function() {

					// var type = $("#seckill_type").val()
					// var url = $("#url").val()
					// var channelid = $("#channelid").val()

					// //alert(type);
					// if(!type || !url || url ==''){
					// 	layer.msg('请先选择一个活动模板');
					// 	return false;
					// }

					// if(!channelid || channelid ==''){
					// 	layer.msg('请先选择一个活动频道');
					// 	return false;
					// }
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['80%', '80%'],
						content: 'p_list.html',
						end: function() {},
						success: function() {}
					});
				}
				window.loadpromotion = function(data) {
					if (data.id) {
						$.get(server.shop_promotion_detail, data, function(res, status) {
							if (status == 'success') {
								if (res.code == 0) {
									var data = res.seckill.data
									res.seckill.data['is_recommend'] = res.seckill.data.recommend
									if (res.seckill_goods && res.seckill_goods.data) {
										data.seckill_goods = res.seckill_goods.data
									}
									setformdata(data, 1);
									// data.data.icon_url ? createli(data.data.icon_url, 'icon_url', '1') : '';
									// data.data.img_url ? createli(data.data.img_url, 'img_url', '2') : '';

									// if(data.data.channelid){
									// 	$("#channelid option[value='"+data.data.channelid+"']").prop("selected","selected");
									// }
									// form.val("test_detail", data.data);
									// form.render();
								} else {
									layer.msg(res.msg);
								}
							} else {
								layer.msg('服务器连接错误');
							}
						});
					}
				}

				window.getdata = function(data, otype) {
					//alert(JSON.stringify(data));
					var type = $("#seckill_type").val()
					var html;
					var a = $("#temp tr").length - 1;
					for (let i in data) {
						if(data[i].type == 0){
							if ($.inArray(data[i].skuid,skuidArr) != -1){
								layer.msg('无法添加已有商品');
								return;
							}
						}
					}
					if (type == 1 || type == 2 || type == 4) { //秒杀 积分
						for (var i = 0; i < data.length; i++) {
							skuidArr.push(Number(data[i].skuid))
							var rowid = 'r' + (Math.random() + i).toString(16).slice(2);
							html += "<tr rowdata='" + escape(JSON.stringify(data[i])) + "' id='" + rowid + "'>" +
							'<td>' + (a + i) + '</td>' +
							'<td><div class="flex"><input  class="layui-input"  name="skuid" value=' + data[i].skuid + ' /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="goods_name" value=' + (data[i].goods_name ? data[i].goods_name : data[i].skuname) + '></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="cost_price" lay-verify="required" value="' + (data[i].cost_price?data[i].cost_price:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="price_member" value=' + data[i].price_member + ' /></div></td>' +
							'<td><div class="flex">' + (otype&&!isNull(data[i].score) ? data[i].score : '-') + '</div></td>' +
							
							'<td><div class="flex"><input  class="layui-input"  name="price" lay-verify="required" value="' + (otype?data[i].price:(data[i].limit_price?data[i].limit_price:''))+ '"/></div></td>' +
							// '<td><div class="flex"><input  class="layui-input"  name="score_scale" lay-verify="required" value="' + ( otype && !isNull(data[i].score_scale) ? data[i].score_scale : 0 ) + '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="score" lay-verify="required" value="' + (otype&& !isNull(data[i].score)?data[i].score:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="stock" lay-verify="required" value="' + (otype&& !isNull(data[i].stock)?data[i].stock:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="sales" value="' + (otype&& !isNull(data[i].sales)?data[i].sales:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="top_count" value="' + (!isNull(data[i].top_count)?data[i].top_count:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="num" value="' + (otype&&!isNull(data[i].num)?data[i].num:'')+ '"/></div></td>' +
							
							'<td><div class="flex"><input  class="layui-input"  name="direct_fee" value="' + (otype&&!isNull(data[i].direct_fee)?data[i].direct_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="indirect_fee" value="' + (otype&&!isNull(data[i].indirect_fee)?data[i].indirect_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="leader_fee" value="' + (otype&&!isNull(data[i].leader_fee)?data[i].leader_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="team_fee" value="' + (otype&&!isNull(data[i].team_fee)?data[i].team_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="copartner_fee" value="' + (otype&&!isNull(data[i].copartner_fee)?data[i].copartner_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="station_fee" value="' + (otype&&!isNull(data[i].station_fee)?data[i].station_fee:'')+ '"/></div></td>' +

							'<td><div class="flex"><input  class="layui-input"  name="oid"  value="' + (otype&&!isNull(data[i].oid)?data[i].oid:(a + i))+ '" /></div></td>' +
							'<td><div class="flex" onclick=delgoods(this,"'+rowid+'")><a href="#">删除</a></div></td>'+
							"<td><div class='flex' id='rowstatus"+rowid+"'></div></td>"+
							'</tr>';
						}
					} else if (type == 3 || type == 6) { //拼团
						for (var i = 0; i < data.length; i++) {
							skuidArr.push(Number(data[i].skuid))
							var rowid = 'r' + (Math.random() + i).toString(16).slice(2);
							html += "<tr rowdata='"+escape(JSON.stringify(data[i]))+"' id='"+rowid+"'>"+
							`<td id="code${data[i].skuid}">` + (a + i) + '</td>' +
							'<td><div class="flex"><input  class="layui-input"  name="skuid" value=' + data[i].skuid + ' /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="goods_name" value=' + (data[i].goods_name ? data[i].goods_name : data[i].skuname) + '></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="cost_price" lay-verify="required"  value="' + (otype&&!isNull(data[i].cost_price)?data[i].cost_price:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="price_member" value=' + data[i].price_member + ' /></div></td>' +
							//'<td><div class="flex"><input  class="layui-input"  name="score_old" lay-verify="required" value="' + (data[i].score?data[i].score:'0')+ '"/></div></td>' +
							
							// `<td><div class="flex"><input onkeyup="inputChange(this, data[i])"  class="layui-input" name="price" lay-verify="required" value="' + (data[i].limit_price?data[i].limit_price:'')+ '"/></div></td>` +
							'<td><div class="flex"><input class="layui-input" name="price" lay-verify="required" value="'+(otype?data[i].price:(!isNull(data[i].limit_price)?data[i].limit_price:''))+'" /></div></td>' +
//							'<td><div class="flex"><input  class="layui-input"  name="score_scale" lay-verify="required" /></div></td>' +
							//'<td><div class="flex"><input  class="layui-input"  name="score" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="subsidy" lay-verify="required"  value="' + (otype&&!isNull(data[i].subsidy)?data[i].subsidy:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="group_num" lay-verify="required"  value="' + (otype&&!isNull(data[i].group_num)?data[i].group_num:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="group_wnum" lay-verify="required"  value="' + (otype&&!isNull(data[i].group_wnum)?data[i].group_wnum:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="group_onum" lay-verify="required"  value="' + (otype&&!isNull(data[i].group_onum)?data[i].group_onum:'')+ '"/></div></td>' +
							
							'<td><div class="flex"><input  class="layui-input"  name="stock" lay-verify="required"  value="' + (otype&&!isNull(data[i].stock)?data[i].stock:'')+ '"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="sales" value="' + (otype&&!isNull(data[i].sales)?data[i].sales:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="top_count" value="' + (otype&&!isNull(data[i].top_count)?data[i].top_count:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="num" value="' + (otype&&!isNull(data[i].num)?data[i].num:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="duration" value="' + (otype&&!isNull(data[i].duration)?data[i].duration:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="launch_fee" value="' + (otype&&!isNull(data[i].launch_fee)?data[i].launch_fee:'')+ '"/></div></td>' +

							'<td><div class="flex"><input class="layui-input" name="group_after_lottery_people" value="' + (otype&&!isNull(data[i].group_after_lottery_people)?data[i].group_after_lottery_people:0)+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="group_after_lottery_skuid" placeholder="点击选择" readonly onclick="choosedata(true, this)" value="' + (otype&&!isNull(data[i].group_after_lottery_skuid)?data[i].group_after_lottery_skuid:'')+ '"/></div></td>' +

							'<td><div class="flex"><input class="layui-input" name="direct_fee" value="' + (otype&&!isNull(data[i].direct_fee)?data[i].direct_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="indirect_fee" value="' + (otype&&!isNull(data[i].indirect_fee)?data[i].indirect_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="leader_fee" value="' + (otype&&!isNull(data[i].leader_fee)?data[i].leader_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="team_fee" value="' + (otype&&!isNull(data[i].team_fee)?data[i].team_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="copartner_fee" value="' + (otype&&!isNull(data[i].copartner_fee)?data[i].copartner_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="station_fee" value="' + (otype&&!isNull(data[i].station_fee)?data[i].station_fee:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" oninput="if(value>8)value=" name="oid" value="' + (otype&&!isNull(data[i].oid)?data[i].oid:(a + i))+ '" /></div></td>' +
							'<td><div class="flex" onclick=delgoods(this,"'+rowid+'")><a href="#">删除</a></div></td>'+
							"<td><div class='flex' id='rowstatus"+rowid+"'></div></td>"+
							'</tr>';
						}
					} else if (type == 5) { //抽奖
						for (var i = 0; i < data.length; i++) {
							skuidArr.push(Number(data[i].skuid))
							var rowid = 'r' + (Math.random() + i).toString(16).slice(2);
							html += "<tr rowdata='"+escape(JSON.stringify(data[i]))+"' id='"+rowid+"'>"+
							`<td id="code${data[i].skuid}">` + (a + i) + '</td>' +
							'<td><div class="flex"><input class="layui-input" name="skuid" value=' + data[i].skuid + ' /></div></td>' +
							'<td><div class="flex"><input class="layui-input" readonly name="goods_type" value="' + data[i].type + '" /></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="goods_name" value=' + (data[i].goods_name ? data[i].goods_name : data[i].skuname) + '></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="stock" lay-verify="required"  value="' + (otype&&!isNull(data[i].stock)?data[i].stock:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="top_count" lay-verify="required"  value="' + (otype&&!isNull(data[i].top_count)?data[i].top_count:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="goods_prize_rate" lay-verify="required"  value="' + (otype&&!isNull(data[i].prize_rate)?data[i].prize_rate:'')+ '"/></div></td>' +
							'<td><div class="flex"><input class="layui-input" name="oid" value="' + (otype&&!isNull(data[i].oid)?data[i].oid:(a + i))+ '" /></div></td>' +
							'<td><div class="flex" onclick=delgoods(this,"'+rowid+'")><a href="#">删除</a></div></td>'+
							"<td><div class='flex' id='rowstatus"+rowid+"'></div></td>"+
							'</tr>';
						}
					}
					$('#tempTr').before(html)
				}
				// 选择活动模板
				window.chooseActive = function() {
					//alert();
					layer.open({
						type: 2,
						title: '选择活动模板',
						shadeClose: false,
						shade: 0.5,
						maxmin: false, //开启最大化最小化按钮
						area: ['90%', '90%'],
						content: 'choose_active_temp.html',
						end: function(data) {},
						success: function(layer, index) {}
					});
				}
				window.selectPromotion = function(data) {
					if (data && data.length) {
						let defaultSub_shopid = localStorage.getItem('pxy_shopid');
						let defaultSub_shopname = localStorage.getItem('pxy_shopname')
						data = data[0];
						skuidArr = [];
						if (data.type == 5) {
							$("#type").hide();
							$("#commission").hide();
							$("#type5").show();
							$('#sub_shop').hide();
						} else if (data.type == 4) {
							$("#type").show();
							$("#commission").show();
							$("#type5").hide();
							$('#sub_shop').show();
							$('#sub_shop').html(`<div class="layui-input-inline" style="width: 180px;">
										<button type="button" class="layui-btn layui-btn-sm" onclick="chooseShop()">选择活动店铺</button>
										&nbsp;&nbsp;活动店铺：
									</div>
									<div class="layui-input-inline" style="width: 150px;">
										<div class="choose_shopname" id="choose_shopname">` + defaultSub_shopname + `</div>
										<input type="hidden" name="subshopid" class="layui-input" lay-verify="` + defaultSub_shopid + `">
										<input type="hidden" name="subshopname" class="sub_shopname" lay-verify="` + defaultSub_shopname + `">
									</div>`);
						} else {
							$("#type").show();
							$("#commission").show();
							$("#type5").hide();
							$('#sub_shop').hide();
							$('#sub_shop').html('');
						}
						let formdata = {
							"url_detail": data.url_detail,
							"istimer": data.istimer,
							"color": data.color,
							"top_count": data.top_count,
							//"endtime": "2023-02-28 10:00:00",
							"recommend": data.recommend,
							//"dates": "2023-02-07",
							"type": data.type,
							"title": data.title,
							"url": data.url,
							"sorted": data.sorted,
							//"times": "10:00:00",
							//"addtime": "2023-02-07 14:27:45",
							"grade": data.grade,
							//"shopname": "团笙元",
							"name": data.name,
							"client": data.client,
							//"shopid": 10005,
							//"id": "1539348e5a854d39852db54ea5c72082",
							//"edit_by": 100000,
							//"edittime": "2023-03-20 08:28:30",
							"status": data.status
						};
						setformdata(formdata);
					}
				}

				// 选择子店铺
				window.chooseShop = function() {
					//alert();
					layer.open({
						type: 2,
						title: '选择店铺',
						shadeClose: false,
						shade: 0.5,
						maxmin: false, //开启最大化最小化按钮
						area: ['90%', '90%'],
						content: 'choose_shop_id.html',
						end: function() {},
						success: function(layer, index) {}
					});
				}
				window.selectShop = function(data) {
					if (data && data.length) {
						data = data[0];
						$('input[name=subshopid]').val(data.sub_shopid);
						$('input[name=subshopname]').val(data.sub_shopname);
						$('#choose_shopname').html(data.sub_shopname);
					}
				}

				window.setformdata = function(formdata, isimprot) {
					if (isimprot) {
						formdata.id = null
						for (var i = 0; i < formdata.seckill_goods.length; i++) {
							formdata.seckill_goods[i].id = null
							formdata.seckill_goods[i].seckill_id = null
						}
					}
					formdata.icon_url ? createli(formdata.icon_url, 'icon_url', '1') : '';
					formdata.img_url ? createli(formdata.img_url, 'img_url', '2') : '';

					if (formdata.channelid) {
						$("#channelid option[value='" + formdata.channelid + "']").prop("selected", "selected");
					}
					if (formdata.client) {
						var client_arr = formdata.client.split(',')
						for (var i = 0; i < client_arr.length; i++) {
							$(".icon_type input[value=" + client_arr[i] + "]").attr("checked", true)
						}
					}
					form.val("test_detail", formdata);
					form.render();

					var getgoodslistTpl = goodslistTpl.innerHTML,
						goodslist = document.getElementById('goodslist');
					laytpl(getgoodslistTpl).render(formdata, function(html) {
						goodslist.innerHTML = html;
					});
					if (formdata.seckill_goods) {
						getdata(formdata.seckill_goods, 1);
					}
				}

				window.delgoods = function(obj, id) {
					layer.confirm('确定要删除商品？', function(index) {
						if (id) {
							var row = $('#' + id);
							var rowdata = JSON.parse(unescape(row.attr("rowdata")));
							if (rowdata.seckill_id && rowdata.id) {
								$.ajax({
									url: server.seckill_goods_delete,
									type: 'post',
									dataType: 'json',
									data: "id=" + rowdata.id,
									success: function(data) {
										if (data.code == '0') {
											row.remove();
											skuidArr.splice($.inArray(rowdata.skuid,skuidArr),1)
											layer.close(index)
											layer.msg('删除成功');
										} else {
											layer.msg('删除失败');
										}
									},
									'error': function() {
										layer.close(index)
										layer.msg('系统错误');
									}
								})
							} else {
								row.remove();
								skuidArr.splice($.inArray(rowdata.skuid,skuidArr),1)
								layer.close(index)
							}
						}
					}, function() {
						layer.msg('取消操作');
					});

				}

				window.getimg = function(data, type) {
					if (data) {
						switch (type) {
							case '1':
								createli(data, 'icon_url', type)
								break;
							case '2':
								createli(data, 'img_url', type)
								break;
							default:
								break;
						}
					}
				}

				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除图片？', function(index) {
						switch (_type) {
							case '1':
								img_arr1.splice(i, 1)
								break;
							case '2':
								img_arr2.splice(i, 1)
								break;
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});

				}

				function createli(data, dom, type) {
					var lihtml = '';
					switch (type) {
						case '1':
							if (data.indexOf(',') == -1) {
								img_arr1.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="z_show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
									'</li>'
							}
							break;
						case '2':
							if (data.indexOf(',') == -1) {
								img_arr2.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr2.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr2.length; i++) {
								lihtml += '<li class="z_show_img_li">' +
									'<img src=' + img_arr2[i] + ' >' +
									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}

				function isNull(str) {
					if (str === null || str === undefined || str.length === 0) {
						return true
					}
					return false
				}
			});
		</script>
	</body>

</html>
